
set(UNILIB_HOME "${CMAKE_SOURCE_DIR}/3rd/unlib")
set(UNILIB_INCLUDE_DIR "${UNILIB_HOME}/unilib")
set(UNILIB_LIBRARY_DIR "${UNILIB_HOME}/lib")

include_directories(
    ${UNILIB_HOME}/unilib
)

file(GLOB_RECURSE UNILIB_SOURCES
    ${UNILIB_HOME}/unilib/*.cpp
)

add_library(unilib SHARED
    ${UNILIB_SOURCES}
)

set(UNILIB_TESTS
    ${UNILIB_HOME}/tests/test_compile.cpp
    ${UNILIB_HOME}/tests/test_conversion.cpp
    ${UNILIB_HOME}/tests/test_strip.cpp
)

message(STATUS "unilib cpp files: ${UNILIB_SOURCES}")
message(STATUS "unilib test cpp files: ${UNILIB_TESTS}")

set(UNILIB_TARGETS unilib)

foreach(test ${UNILIB_TESTS})
    get_filename_component(TEST_NAME ${test} NAME)
    message(STATUS "unilib test name: ${TEST_NAME}")
    add_executable(${TEST_NAME} ${test})
    target_link_libraries(${TEST_NAME} unilib)
    list(APPEND UNILIB_TARGETS ${TEST_NAME})
endforeach()

message(STATUS "UNILIB_TARGETS: ${UNILIB_TARGETS}")

install(TARGETS ${UNILIB_TARGETS}
    RUNTIME DESTINATION bin
    LIBRARY DESTINATION lib
    ARCHIVE DESTINATION lib
)

file(GLOB_RECURSE UNILIB_HEADERS
    ${UNILIB_HOME}/unilib/*.h)

foreach(header ${UNILIB_HEADERS})
    # get_filename_component(HEADER_NAME ${header} NAME)
    install(FILES ${header} DESTINATION include/unilib)
endforeach()